<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    .addbut{position: absolute;right:9px;top: 9px;height: 34px;line-height: 34px!important;width:37px;padding:0 3px;background-color: #1ca5ff;}
    .guanbut{position: absolute;right:9px;top: 9px;height: 34px;line-height: 34px!important;width:37px;padding:0 3px;background-color: red!important;color: #FFFFFF}
</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con">
            <span>新建授权委托书申请</span><div class="move_title"></div><?php include "../public/subturn.php";?></div>
    </div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="bidid" class="layui-input bidid" onclick="choose_bid()">
                            <div class="choose_div" id="bidid"></div>
                            <span class="choose_one" onclick="choose_bid()">
                                <i class="layui-icon layui-icon-search"></i>
                            </span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目属性</label>
                        <div class="layui-input-block">
                            <input type="text" id="bid_number" class="layui-input disabled" disabled>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>对方单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="duiunit" id="duiunit" clearable class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>我方单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="weunit" id="weunit" clearable class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>授权委托人</label>
                        <div class="layui-input-block" style="position: relative;">
                            <input type="text" name="name[]" id="name" class="layui-input">
                            <button type="button" class="layui-btn addbut" onclick="add_row()">
                                <i class="layui-icon layui-icon-addition"></i>
                            </button>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">证件号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="number[]" id="number" clearable class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" id="box">
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>用途</label>
                        <div class="layui-input-block">
                            <input type="text" name="purpose" id="purpose" clearable class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">委托有效期</label>
                        <div class="layui-input-block">
                            <input type="text" name="startdt" id="startdt" clearable class="layui-input bdate_ymd" style="width: 48%;float: left;">
                            <span style="width: 4%;float: left;text-align: center;padding-top: 7px;"> - </span>
                            <input type="text" name="enddt" id="enddt" clearable class="layui-input bdate_ymd" style="width: 48%;float: left;">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea" id="explain_label">委托说明</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
<!--            <div class="layui-form-item height_auto">-->
<!--                <div class="layui-row layui-col-space10">-->
<!--                    <div class="layui-col-md12">-->
<!--                        <label class="layui-form-label"><text>*</text>内容</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <div style="border: 1px solid #e3e3e3;">-->
<!--                                <div id="toolbar-container" style="z-index: 101;"></div>-->
<!--                                <div id="editor-container" style="height: 300px;z-index: 100;"></div>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>

    </div>
</form>
<script>
    // 选择项目
    function choose_bid() {
        openPage('../public/choose_bid.php?page=bid_grant_book&dom=bidid','80%','80%')
    }

    // 移除
    function remove_row(obj){
        $(obj).parent().parent().remove();

        $('#box>div').each(function (index) {
            $(this).find('.weitui').text('授权委托人'+(index+1));
        })
    }
    // 新增
    function add_row(){
        var index = $('#box>div').length;

        var str = '';
        str += '<div class="layui-row layui-col-space10">';
        str += '<div class="layui-col-md6">';
        str += '<label class="layui-form-label weitui">授权委托人'+(index+1)+'</label>';
        str += '<div class="layui-input-block" style="position: relative;">';
        str += '<input type="text" name="name[]" id="name" clearable class="layui-input">';
        str += '</div>';
        str += '</div>';
        str += '<div class="layui-col-md6">';
        str += '<label class="layui-form-label">证件号码</label>';
        str += '<div class="layui-input-block" style="margin-left: 0 !important;width: calc(100% - 156px) !important;float: left;">';
        str += '<input type="text" name="number[]" id="number" clearable class="layui-input">';
        str += '</div>';


        // str += '<span  onclick="remove_row(this)"><i class="layui-icon layui-icon-close"></i></span>';
        str += '<button type="button" class="layui-btn guanbut" onclick="remove_row(this)"><i class="layui-icon layui-icon-close"></i></button>';
        str += '</div>';
        str += '</div>';
        $('#box').append(str);
    }

    $("#commentForm").validate({
        rules: {
            duiunit: {required: true},
            weunit: {required: true},
            purpose: {required: true},
        },
        messages:{
            duiunit: {required: "请输入对方单位"},
            weunit: {required: "请输入我方单位"},
            purpose: {required: "请输入用途"},
        }
    });

    // 编辑框初始化
    // const editorConfig = {MENU_CONF: {'uploadImage':{base64LimitSize: 5000 * 1024}}};
    // const editor = window.wangEditor.createEditor({selector: '#editor-container', config: editorConfig, mode: 'simple'});
    // const toolbar = window.wangEditor.createToolbar({editor, selector: '#toolbar-container', mode: 'simple'});

    layui.use(['laytp', 'form'], function() {
        var form = layui.form;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_bid_grant_book}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }

                public_upload_file_load('upload_files');
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            // data.field.content = editor.getHtml();

            data.field.bidid = get_choose_val('bidid');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                if(!validRes){return false;}

                // if(data.field.content == "<p><br></p>"){
                //     facade.error("请输入内容");return false;
                // }
            }

            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_bid_grant_book, ask_flowdata_edit_bid_grant_book, $(this).attr('but'));
            return false;
        });
    });
</script>
</body>
</html>
